<?php
if(!$login_do) include("config.php");
if($_POST['session_id']){
	
	//////////////////////////////////////////////////////////////////////////////////////
	//获取成绩单
	//先获取成绩查询表单，分析其中txt_xm字段
	$snoopy2 = new Snoopy;
	//模拟HEADER
	$snoopy2->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//获取分析表单
	$snoopy2->fetchform($scoreformurl);	
	//超时返回
	if ($snoopy2->status != '200' || $snoopy2->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}
	$res2 = $snoopy2->results;
	$txt_xm = substr($res2[16], 39, -1);

	//获取成绩单
	$snoopy3 = new Snoopy;
	//定义POST内容
	$submit_vars3["SelXNXQ"] = "0";
	$submit_vars3["SJ"] = "0";
	$submit_vars3["txt_xm"] = $txt_xm;
	$submit_vars3["zfx_flag"] = "0";
	//模拟HEADER
	$snoopy3->cookies['ASP.NET_SessionId'] = $_SESSION["ASP_NET_SessionId"];
	//提交
	$snoopy3->submit($scoreurl,$submit_vars3);		
	//超时返回
	if ($snoopy3->status != '200' || $snoopy3->timed_out) {
    	echo json_err(1,"页面获取超时！");
    	return;
	}
	//转码以便查找错误
	$snoopy_results = mb_convert_encoding($snoopy3->results, 'utf-8', 'gbk');
	if(stripos($snoopy_results,"您正查看的此页已过期")){
    	echo json_err(5,"session_id错误或超时！");
    	return;
	}
	if(strpos($snoopy_results, "Sorry_note")){
		echo json_err(5,'Sorry_note!');
		return;
	}
	$score_result = $snoopy_results;
	//TODO 分析结果，输出为json
	echo $score_result;
	return;
	//记录
	//$query = "UPDATE log SET user_id='".$_POST['UserID']."',is_ok='".$is_ok."',num='".$txt_xm."' WHERE id='".$_SESSION['insert_id']."'";
	//mysql_query($query);

}else{
	echo json_err(2,'提交数据不全!');
	return;
}
//mysql_close($link);
?>